package persistent;

import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.net.InetAddress;
import java.net.Socket;
import java.util.Date;

import painter.PainterClient;

import frame.Frame;


public class PersistentClient {

	private static final int PORT_PAINTER_RECEP = 5825;
	
	protected Socket frameSocket = null;
	
	private Frame f;
	
	public PersistentClient(Frame f) throws IOException{
		
		InetAddress address = InetAddress.getByName("localhost");
		frameSocket = new Socket(address, PORT_PAINTER_RECEP);
		
		this.f = f;
	}
	
	public void sendFrame() throws IOException{
		
		ObjectOutputStream oos = new ObjectOutputStream(frameSocket.getOutputStream());
		
		oos.writeObject(f);
		
		System.out.println("request sent");
		
		boolean response = false;
		
		ObjectInputStream ois = new ObjectInputStream(frameSocket.getInputStream());
		response = ois.readBoolean();
		
		System.out.println(response);
		
		frameSocket.close();
	}
	
	public static void main(String[] args) {
		
		Frame f = new Frame();
		
		f.setFecha(new Date());
		
		try {
			PersistentClient psc = new PersistentClient(f);
			psc.sendFrame();
		} 
		catch (IOException e) {
			e.printStackTrace();
		}
	}


}
